home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / logdaemon-2 / lib / utmpx_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-31  |  1.1 KB  |  52 lines

  1. /* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
  2.  
  3. #include <sys/types.h>
  4. #include <sys/time.h>
  5. #include <utmpx.h>
  6. #include <string.h>
  7. #include <syslog.h>
  8.  
  9. /* utmpx_init - update utmp and wtmp before login */
  10.  
  11. utmpx_init(line, user, id)
  12. char   *line;
  13. char   *user;
  14. char   *id;
  15. {
  16.     struct utmpx utx;
  17.  
  18.     memset((char *) &utx, 0, sizeof(utx));
  19.     strncpy(utx.ut_id, id, sizeof(utx.ut_id));
  20.     strncpy(utx.ut_user, user, sizeof(utx.ut_user));
  21.     strncpy(utx.ut_line, line, sizeof(utx.ut_line));
  22.     utx.ut_pid = getpid();
  23.     utx.ut_type = LOGIN_PROCESS;
  24.     gettimeofday(&(utx.ut_tv));
  25.     pututxline(&utx);
  26.     updwtmpx(WTMPX_FILE, &utx);
  27.     endutxent();
  28. }
  29.  
  30. /* utmpx_ptsid - generate utmp id for pseudo terminal */
  31.  
  32. char   *utmpx_ptsid(line, tag)
  33. char   *line;
  34. char   *tag;
  35. {
  36.     int     num;
  37.     static char buf[4];
  38.  
  39.     /*
  40.      * Derive utmp ID from pty slave number and application-specific tag.
  41.      * SYSV4 uses a different but undocumented algorithm.
  42.      */
  43.  
  44.     if (sscanf(line, "%*[^0-9]%d", &num) != 1 || num > 255) {
  45.     syslog(LOG_ERR, "unparseable pty slave name: %s", line);
  46.     _exit(1);
  47.     }
  48.     sprintf(buf, "%.2s%02x", tag, num);
  49.     return (buf);
  50. }
  51.  
  52.